package www.geek.filemanager.base;

import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;


/**
 * Fragment 基类
 */

public class BaseFragment extends Fragment implements AdapterView.OnItemClickListener, View.OnClickListener, BaseFragmentInterface {

    protected LayoutInflater mInflater;
    private Dialog netDialog;
    private final int HANDLER_MSG_TAG_NETDIALOG_SHOW = 1;

    private final int HANDLER_MSG_TAG_NETDIALOG_CANCLE = 2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        this.mInflater = inflater;
        View view = super.onCreateView(inflater, container, savedInstanceState);
        return view;
    }


    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    protected int getLayoutId() {
        return 0;
    }

    protected View inflateView(int resId) {
        return this.mInflater.inflate(resId, null);
    }


    public void showNetDialog() {

        Message msg = handler.obtainMessage();
        msg.what = HANDLER_MSG_TAG_NETDIALOG_SHOW;
        handler.sendMessage(msg);

    }

    public void cancelNetDialog() {
        Message msg = handler.obtainMessage();
        msg.what = HANDLER_MSG_TAG_NETDIALOG_CANCLE;
        handler.sendMessage(msg);
    }

    private void initNetDialog() {
//        netDialog = ToastUtils.showToastDialogNoClose(DoctorApp.getmActivityContext(), "正在加载中..",
//                ToastUtils.TOAST_LOADING, true);
    }


    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case HANDLER_MSG_TAG_NETDIALOG_SHOW:
                    if (netDialog == null) {
                        initNetDialog();
                    }
                    if (!netDialog.isShowing()) {
                        netDialog.show();
                    }
                    break;
                case HANDLER_MSG_TAG_NETDIALOG_CANCLE:
                    if (netDialog == null) {
                        return;
                    }
                    if (netDialog.isShowing())
                        netDialog.dismiss();
                    break;
            }
        }
    };

    @Override
    public void initView(View view) {

    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }
}
